﻿using DocumentFormat.OpenXml.Lite.Core.Office;
using DocumentFormat.OpenXml.Lite.WordprocessingML.Word.Base;
using DocumentFormat.OpenXml.Lite.WordprocessingML.Word.ParagraphProperties;
using DocumentFormat.OpenXml.Lite.WordprocessingML.Word.SectionProperties;
using DocumentFormat.OpenXml.Lite.WordprocessingML.Word.Types;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Samples.Word
{
    class Headers
    {
        public static void Create()
        {
            Document doc = DocumentManager.Instance.CreateWordDocument();

            doc.CreateBody().AddParagraph().AddRun().AddSimpleText("Docx sample with header.");
            Paragraph propP = doc.Body.AddParagraph();

            Header header = doc.CreateHeader();

            propP.AddSectionProperty(new HeaderReference()
            {
                Type = ST_HdrFtr.Default,
                RelationshipId = header.RelationshipId,
            });

            Paragraph p = header.AddParagraph();
            p.AddRun().AddSimpleText("Header");
            p.AddProperty(new ParagraphAlignment() { Value = ST_Jc.Center });

            doc.Save(@"samples\header.docx");

            Document parsed = null;
            if (DocumentManager.Instance.OpenWordDocument(@"samples\header.docx", out parsed))
            {
                Console.WriteLine("Sample created and parsed succesfully!");
            }
            Console.ReadLine();
        }
    }
}
